Ext.onReady(function () {
    //this.appname = 'appfe';
    // 设置button menu 的时候在console中显示错误，加了这句就好了。
    // 参阅此处 https://docs.sencha.com/extjs/6.0/whats_new/6.0.0/extjs_upgrade_guide.html#Button
    Ext.enableAriaButtons = false;
    // 如果一个 panel 没有设置title，会在console里面显示一个警告信息，加上这个就没了
    Ext.enableAriaPanels = false;
    //设定appfe命名空间的目录为assets/appfe
    // Ext.Loader.setConfig({
    //     enabled: true,
    //     disableCaching: true,
    //     paths: {
    //         'appfe': 'assets/appfe'
    //     }
    // });

    //Ext.USE_NATIVE_JSON = true;
    Ext.ariaWarn = Ext.emptyFn;
    Ext.tip.QuickTipManager.init(); // Instantiate the QuickTipManager
    Ext.form.Field.prototype.msgTarget = 'side';
    delete Ext.tip.Tip.prototype.minWidth; // 防止tooltip的宽度很小，不好看

    console.debug('echarts.version:%s', echarts.version);
    console.debug('sys_version:', sys_version);
    
    /*
    try {
        var objTest = { aaa: 111 };
        var bbb = objTest['bbb'];
        console.debug('objTest', objTest);
        console.debug('objTest[aaa]', objTest['aaa']);
        console.debug('objTest[bbb]', objTest['bbb']);
        console.debug('Ext.typeOf(objTest)', Ext.typeOf(objTest));
        console.debug('Ext.typeOf({})', Ext.typeOf({}));
        console.debug('Ext.typeOf([])', Ext.typeOf([]));
        console.debug('Ext.typeOf(11)', Ext.typeOf(11));
        console.debug('Ext.typeOf(\'\')', Ext.typeOf(''));
        console.debug('Ext.typeOf(objTest[\'bbb\'])', Ext.typeOf(objTest['bbb']));
        console.debug('Ext.typeOf(bbb)', Ext.typeOf(bbb));

        console.debug('Ext.Object.isEmpty(objTest)', Ext.Object.isEmpty(objTest));
        console.debug('Ext.Object.isEmpty(null)', Ext.Object.isEmpty(null));
        console.debug('Ext.Object.isEmpty(\'\')', Ext.Object.isEmpty(''));
        console.debug('Ext.Object.isEmpty({})', Ext.Object.isEmpty({}));
        console.debug('Ext.Object.isEmpty([])', Ext.Object.isEmpty([]));
    } catch (e) { console.error(e); }
    */
});
Ext.define('appfe.Application', {
    extend: 'Ext.app.Application',
    
    name: 'appfe',

    stores: [
        'NavigationTree'
    ],
    defaultToken : 'home',

    // The name of the initial view to create. This class will gain a "viewport" plugin
    // if it does not extend Ext.Viewport.
    //
    mainView: 'appfe.view.main.Main',

    launch: function () {
        // try {
        //     window.console && window.console.debug
        //         && (console.debug("%c学习,\n思考,\n勤奋,\n自律!", "color:green;font-size:18px;font-weight: bold;text-decoration: underline;"),
        //             console.debug("%c聚商宝:https://www.zinbiz.com", "color:red;"))
        // } catch (e) { }

        var loggedIn;
        loggedIn = localStorage.getItem("TutorialLoggedIn");
        console.debug('Applacation launch localStorage loggedIn:', loggedIn);
        if (!loggedIn) {
            window.location = '#login';
            // Ext.create({
            //     //xtype: loggedIn ? 'app-main' : 'login'
            //     xtype: 'login'
            // });
            // return;
        }
        console.debug('Applacation launch 发起checkauth');
        Ext.Ajax.request({
            url: BizHttpAction.checkauth.url,
            method: BizHttpAction.checkauth.method,
            success: function (response, opts) {
                console.debug('Application.launch checkauth HTTP:success RESP:success=true');
                var respObj = Ext.JSON.decode(response.responseText);
                if (respObj.success) {
                    //window.location = '#home';
                } else {
                    console.debug('Application.launch checkauth HTTP:success RESP:success=false');
                    Ext.Msg.alert("提示", respObj.message);
                    window.location = '#login';
                }
            },
            failure: function (response, opt) {
                console.debug('Application.launch checkauth failure');
                window.location = '#login';
                //alert("数据加载失败，请联系系统管理员");
            }
        });
        appfe.ux.GlobalParam.myGlobal = 2; //variables in singleton are auto static.
    },
    getHashValue: function (key) {
        var matches = location.hash.match(new RegExp(key + '=([^&]*)'));
        return matches ? matches[1] : null;
    },
    addToolTip: function (id, msg) {
        new Ext.ToolTip({
            target: id,
            dismissDelay: 0,
            anchor: 'right',
            html: msg
        });
    },
    onAppUpdate: function () {
        Ext.Msg.confirm('Application Update', 'This application has an update, reload?',
            function (choice) {
                if (choice === 'yes') {
                    window.location.reload();
                }
            }
        );
    }
});
